Skip to content


ai  101  pytorch  classification  nvidia  cuda  install  tensorrt  yolo  ardupilot  None  ros2  dds  micro ros  xrce  sitl  plugin  SITL  debug  rangefinder  pymavlink  mavros  gazebo  distance sensor  system_time  timesync  cmake  gtest  ctest  cpp  c++  format  fmt  multithreading  spdlog  camera  coordinate system  orb  matching  opencv  build  transformation  computer vision  homography  optical flow  of  trackers  cv  cyclonedds  eprosima  fastdds  simulation  config  ignition  bridge  sdf  tips  ign-transport  sensors  lidar  aptly  apt  encryption  pgp  docker  git  bundle  github  hooks  pre-commit  lxd  container  lxc  x11  profile  vscode  marpit  presentation  marp  markdown  mermaid  video  ffmpeg  gstreamer  cheat-sheet  sdp  v4l2loopback  gi  snippets  cheat Sheet  python  asyncio  future  click  cli  numpy  project  template  black  isort  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  mock  iterator  generator  logging  tuple  namedtuple  typing  annotation  pyzmq  zmq  msgpack  action  namespace  remap  control2  ros2_control  gdb  qos  tag  plugins  msg  node  zero-copy  shm  tutorial  algorithm  calibration  diff  pid  dev  colcon  colcon_cd  rpi  arm  qemu  settings  behavior  plot  visualization  debugging  diagnostic  diagnostics  tutorials  gst  math  apm  rat_runtime_monitor  web  rosbridge  vue  binding  discovery  gazebo-classic  launch  spawn  cook  gps  imu  ray  gazebo_ros_ray_sensor  ultrsonic  range  ultrasonic  gazebo classic  wrench  effort  odom  ign  gz  xacro  ros_ign  diff_drive  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  nav  slam  test  rclpy  executor  MultiThreadedExecutor  SingleThreadedExecutor  param  dynamic-reconfigure  service  client  setup.py  package.xml  parameter  parameters  custom  msgs  executers  pub  sub  rqt  rviz  rviz2  pose  marker  tf2  deb  package  setup  local_setup  rosdep  package manager  project settings  vcstool  cross-compiler  nano  texture  tmuxp  rootfs  embedded  zah  linux  rm  ubuntu  udev  ip  ss  network  netstat  snap  deploy  ssh  systemd  mkdocs  extensions  socat  networking  serial  udp  tc  mtu  select  px4  robotics  kalman_filter  kalman  filter  control  todo  vscode-ext  json  yaml  schema  yocto  poky  world  gazebo_ros2_control  position_controller  effort_controller  velocity_controller  urdf  gazebo_ros_force  gazebo_ros_joint_state_publisher  robot_state_publisher  joint_state_publisher  projects  vrx  buoyancy 

Run ROS2 Node#

Run minimal ROS2 node from:

  • cli
  • add namespace
  • remap topic
  • remap node name
  • launch file
  • cli control debug level

Run from cli#

ros2 run params_demos minimal
#
[INFO] [1680205241.556490384] [simple_param_node]: my_int: 3
[INFO] [1680205242.543293520] [simple_param_node]: my_int: 2
[INFO] [1680205243.543186445] [simple_param_node]: my_int: 1
[INFO] [1680205244.543174591] [simple_param_node]: close timer
ros2 node list
# 
/simple_param_node

Add namespace#

terminal 1
ros2 run params_demos minimal --ros-args --remap __ns:=/custom
terminal 2
ros2 node list           
#
/custom/simple_param_node

Remap topic name#

terminal 1
# without namespace
ros2 run params_demos minimal --ros-args --remap /simple_param_node/my_topic:=/new_topic

# with namespace
ros2 run params_demos minimal --ros-args --remap /custom/simple_param_node/my_topic:=/new_topic --remap __ns:=/custom
terminal 2
ros2 node list           
#
/custom/simple_param_node

ros2 topic list 
#
/new_topic

Topic absolute name

topic name start with forward slash are absolute
when you rename topic and the remap topic name are not absolute. namespace add to the topic name as prefix

ros2 run params_demos minimal --ros-args --remap /custom/simple_param_node/my_topic:=new_topic --remap __ns:=/custom

ros2 topic list 
#
/custom_ns/new_topic
ros2 run params_demos minimal --ros-args --remap /custom/simple_param_node/my_topic:=/new_topic --remap __ns:=/custom

ros2 topic list 
#
/new_topic

Add fqn to topic name

Topic and Service name mapping to DDS

fqn = self.get_fully_qualified_name()
self.get_logger().info(f"node name: {node_name}")
self.pub = self.create_publisher(Int32, fqn + TOPIC, 10)

Remap node name#

Terminal 1
ros2 run params_demos minimal --ros-args --remap __node:=node_new_name
Terminal 2
ros2 node list
#
/node_new_name

ros2 topic list
#
/node_new_name/my_topic
/parameter_events
/rosout

Remap node name with namespace#

Terminal 1
run params_demos minimal --ros-args --remap __node:=node_new_name --remap __ns:=/custom
Terminal 2
ros2 node list 
#
/custom/node_new_name

ros2 topic list
#
/custom/node_new_name/my_topic
/parameter_events
/rosout

Note

name = self.get_name()
ns = self.get_namespace()
fqn = self.get_fully_qualified_name()
self.get_logger().info(f"node name: {name}")
self.get_logger().info(f"ns: {ns}")
self.get_logger().info(f"fqn: {fqn}")
ros2 run params_demos minimal --ros-args --remap __node:=node_new_name --remap __ns:=/custom
[INFO] [1680233355.573926310] [custom.node_new_name]: node name: node_new_name
[INFO] [1680233355.574155685] [custom.node_new_name]: ns: /custom
[INFO] [1680233355.574342657] [custom.node_new_name]: fqn: /custom/node_new_name

launch#

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    ld = LaunchDescription()

    sim_node =  Node(
            package='params_demos',
            namespace='custom',
            executable='minimal',
            name='simple_node'
        )


    ld.add_action(sim_node)
    return ld
ros2 node list
/custom/simple_node
#
ros2 topic list
/custom/simple_node/my_topic

remap topics#

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    ld = LaunchDescription()

    sim_node =  Node(
            package='params_demos',
            namespace='custom',
            executable='minimal',
            name='simple_node',
            remappings=[
                ("/custom/simple_node/my_topic", "/new_topic_name")
            ]
        )


    ld.add_action(sim_node)
    return ld
ros2 node list
/custom/simple_node
#
ros2 topic list
/new_topic_name

cli and launch logging level control#

more ros2 logging info

cli#

loging level:

  • debug
  • info
  • warn
  • error
terminal
ros2 run params_demos minimal --ros-args --log-level debug

launch#

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    ld = LaunchDescription()

    sim_node =  Node(
            package='params_demos',
            namespace='custom',
            executable='minimal',
            name='simple_node',
            remappings=[
                ("/custom/simple_node/my_topic", "/new_topic_name")
            ],
            arguments=['--ros-args', '--log-level', 'warn']
        )


    ld.add_action(sim_node)
    return ld

Reference#